10 CLS:RANDOMIZE TIMER:DEFINT A-Z:KEY OFF:WIDTH 40
20 SC#=0:DIM B(4,4),S(16,2):SL=0:ACT=0
30 COLOR 9:LOCATE 8,9,0:PRINT CHR$(218);STRING$(21,196);CHR$(191);
40 FOR I=1 TO 9:LOCATE 8+I,9:PRINT CHR$(179);SPC(21);CHR$(179);:NEXT I
50 LOCATE 18,9:PRINT CHR$(192);STRING$(21,196);CHR$(217);
60 COLOR 14:LOCATE 6,10:PRINT "Score:";
70 KEY 15,CHR$(128)+CHR$(72):KEY 16,CHR$(128)+CHR$(75):KEY 17,CHR$(128)+CHR$(77):KEY 18,CHR$(128)+CHR$(80)
71 ON KEY(11) GOSUB 160:ON KEY(12) GOSUB 161:ON KEY(13) GOSUB 162:ON KEY(14) GOSUB 163
72 ON KEY(15) GOSUB 160:ON KEY(16) GOSUB 161:ON KEY(17) GOSUB 162:ON KEY(18) GOSUB 163
73 FOR I=11 TO 18:KEY(I)ON:NEXT I
80 GOSUB 600:WHILE SL>0:K$=INKEY$
90 IF K$=CHR$(27) THEN GOTO 150 ELSE ON ACT GOSUB 200,300,400,500
100 IF ACT=5 THEN ACT=0
120 WEND
130 SOUND 100,2:LOCATE 20,16:COLOR 12:PRINT "GAME OVER";
140 FOR I=11 TO 18:KEY(I)OFF:NEXT I:WHILE INPUT$(1)<>CHR$(27):WEND
150 COLOR 7:CLS:WIDTH 80:END
160 IF ACT<>5 THEN ACT=1:RETURN ELSE RETURN
161 IF ACT<>5 THEN ACT=2:RETURN ELSE RETURN
162 IF ACT<>5 THEN ACT=3:RETURN ELSE RETURN
163 IF ACT<>5 THEN ACT=4:RETURN ELSE RETURN
200 ACT=5:M=0:FOR X=0 TO 3:Y0=0:Y=1:WHILE Y<=3
202 IF B(Y0,X)<>0 THEN GOTO 210
203 IF B(Y,X)<>0 THEN B(Y0,X)=B(Y,X):B(Y,X)=0:M=1
204 Y=Y+1:GOTO 290
210 IF B(Y,X)=0 THEN Y=Y+1:GOTO 290 ELSE IF B(Y0,X)=B(Y,X) THEN GOTO 220
211 Y0=Y0+1:IF Y0=Y THEN Y=Y+1
212 GOTO 290
220 SC#=SC#+B(Y,X):B(Y0,X)=B(Y0,X)*2:B(Y,X)=0:Y0=Y0+1:Y=Y+1:M=1
290 WEND:NEXT X:IF M=1 THEN GOTO 600 ELSE RETURN
300 ACT=5:M=0:FOR Y=0 TO 3:X0=0:X=1:WHILE X<=3
302 IF B(Y,X0)<>0 THEN GOTO 310
303 IF B(Y,X)<>0 THEN B(Y,X0)=B(Y,X):B(Y,X)=0:M=1
304 X=X+1:GOTO 390
310 IF B(Y,X)=0 THEN X=X+1:GOTO 390 ELSE IF B(Y,X0)=B(Y,X) THEN GOTO 320
311 X0=X0+1:IF X0=X THEN X=X+1
312 GOTO 390
320 SC#=SC#+B(Y,X):B(Y,X0)=B(Y,X0)*2:B(Y,X)=0:X0=X0+1:X=X+1:M=1
390 WEND:NEXT Y:IF M=1 THEN GOTO 600 ELSE RETURN
400 ACT=5:M=0:FOR Y=0 TO 3:X0=3:X=2:WHILE X>=0
402 IF B(Y,X0)<>0 THEN GOTO 410
403 IF B(Y,X)<>0 THEN B(Y,X0)=B(Y,X):B(Y,X)=0:M=1
404 X=X-1:GOTO 490
410 IF B(Y,X)=0 THEN X=X-1:GOTO 490 ELSE IF B(Y,X0)=B(Y,X) THEN GOTO 420
411 X0=X0-1:IF X0=X THEN X=X-1
412 GOTO 490
420 SC#=SC#+B(Y,X):B(Y,X0)=B(Y,X0)*2:B(Y,X)=0:X0=X0-1:X=X-1:M=1
490 WEND:NEXT Y:IF M=1 THEN GOTO 600 ELSE RETURN
500 ACT=5:M=0:FOR X=0 TO 3:Y0=3:Y=2:WHILE Y>=0
502 IF B(Y0,X)<>0 THEN GOTO 510
503 IF B(Y,X)<>0 THEN B(Y0,X)=B(Y,X):B(Y,X)=0:M=1
504 Y=Y-1:GOTO 590
510 IF B(Y,X)=0 THEN Y=Y-1:GOTO 590 ELSE IF B(Y0,X)=B(Y,X) THEN GOTO 520
511 Y0=Y0-1:IF Y0=Y THEN Y=Y-1
512 GOTO 590
520 SC#=SC#+B(Y,X):B(Y0,X)=B(Y0,X)*2:B(Y,X)=0:Y0=Y0-1:Y=Y-1:M=1
590 WEND:NEXT X:IF M=1 THEN GOTO 600 ELSE RETURN
600 SL=0:COLOR 14:LOCATE 6,16:PRINT SC#;:COLOR 15
610 FOR Y=0 TO 3:LOCATE (10+Y*2),10:FOR X=0 TO 3
620 IF B(Y,X)<>0 THEN PRINT USING "#####";B(Y,X); ELSE PRINT "    .";:S(SL,0)=Y:S(SL,1)=X:SL=SL+1
630 NEXT X:NEXT Y:IF SL=0 THEN RETURN
650 SE=INT(RND*20) MOD SL:Y=S(SE,0):X=S(SE,1):B(Y,X)=((INT(RND*10) MOD 2)+1)*2
660 LOCATE 10+2*Y,10+5*X:PRINT USING "#####";B(Y,X);:IF SL>1 THEN RETURN
670 FOR Y=0 TO 3:FOR X=0 TO 3
671 IF X<3 THEN IF B(Y,X)=B(Y,X+1) THEN RETURN
672 IF Y<3 THEN IF B(Y,X)=B(Y+1,X) THEN RETURN
680 NEXT X:NEXT Y:SL=0:RETURN
